package com.heihei.common.response;

import java.text.MessageFormat;
import java.util.HashMap;


public class ResponseDataWrapper {
	/** 成功 */
	public static final ResponseDataWrapper SUCC = new ResponseDataWrapper(200, "OK");

	/** 通用错误提示信息 */
	public static final ResponseDataWrapper FAILURE = new ResponseDataWrapper(400, "警告");
	public static final ResponseDataWrapper NOT_LOGIN = new ResponseDataWrapper(401, "未登录");
	public static final ResponseDataWrapper LOGIN_FAIL = new ResponseDataWrapper(402, "用户名或者密码错误");
	public static final ResponseDataWrapper LOGIN_TOKEN_ISVALID = new ResponseDataWrapper(403, "token无效");
	public static final ResponseDataWrapper SYSTEM_ERROR = new ResponseDataWrapper(500, "系统错误");
	public static final ResponseDataWrapper PARAM_LESS_ERROR = new ResponseDataWrapper(600, "缺少参数");

	public static final ResponseDataWrapper PARAM_UNVALID = new ResponseDataWrapper(618, "非法参数");

	public static final ResponseDataWrapper ID_IS_NULL = new ResponseDataWrapper(700, "主键不能为空");
	public static final ResponseDataWrapper RESOURCE_NOT_EXIST = new ResponseDataWrapper(701, "未找到记录");
	public static final ResponseDataWrapper AUDITING_CANT_UPDATE = new ResponseDataWrapper(700, "审核中，无法修改");
	public static final ResponseDataWrapper AUDITING_CANT_DELETE = new ResponseDataWrapper(700, "审核中，无法删除");

	/** 记录不存在或已被删除提示信息 */
	public static final ResponseDataWrapper RECORD_NO_EXIST_OR_DELETED = new ResponseDataWrapper(702, "记录不存在或已被删除");
	public static final ResponseDataWrapper RECORD_EXIST = new ResponseDataWrapper(703, "记录已存在");
	/**
	 * 开发中如需新增返回CODE,需按照功能模块划分，例如用户相关100xx、设备相关101xx，输入对应编码，提示信息即可。如下所示
	 */
	public static ResponseDataWrapper USER_NOT_EXIST = new ResponseDataWrapper(10001, "用户不存在");
	public static ResponseDataWrapper USER_EXIST = new ResponseDataWrapper(10002, "用户已存在");
	public static ResponseDataWrapper ROLE_CANT_DELETE = new ResponseDataWrapper(10001, "该角色已和用户绑定，无法删除！");
	public static ResponseDataWrapper MOBILE_EXIST = new ResponseDataWrapper(10003, "该手机号已存在");
	public static ResponseDataWrapper EMAIL_EXIST = new ResponseDataWrapper(10004, "该邮箱已存在");

	/** 资产模块 */
	public static ResponseDataWrapper STORAGE_CANT_DELETE = new ResponseDataWrapper(10501, "仓库仍有物资，不能删除！");

	/** 文件格式  **/
	public static ResponseDataWrapper FILE_FORMAT = new ResponseDataWrapper(10601, "上传文件格式不正确！");
	public static ResponseDataWrapper RELATION_MODEL_EXIST = new ResponseDataWrapper(10602, "已关联模型！");

	/** 设备维修计划模块 */
	public static ResponseDataWrapper MAINTENANCEPLAN_NOT_EXIST = new ResponseDataWrapper(10701, "维修计划不存在！");
	public static ResponseDataWrapper MAINTENANCEPLAN_DISPATCHING_NOT_EXIST = new ResponseDataWrapper(10702, "派工记录不存在！");

	/** 安全质量模块通用增删改错误返回信息 **/
	public static ResponseDataWrapper OBJECT_INSERT_ERROR = new ResponseDataWrapper(10801, "添加失败！");
	public static ResponseDataWrapper OBJECT_UPDTE_ERROR = new ResponseDataWrapper(10802, "更新失败！");
	public static ResponseDataWrapper OBJECT_DELETE_ERROR = new ResponseDataWrapper(10803, "删除失败！");

	/** 工单模块 */
	public static ResponseDataWrapper WORK_ORDER_NOT_EXIST = new ResponseDataWrapper(10901, "工单不存在！");
	public static ResponseDataWrapper WORK_ORDER_DISPATCHING_NOT_EXIST = new ResponseDataWrapper(10902, "派工记录不存在！");

	public static ResponseDataWrapper WARN_INFO = new ResponseDataWrapper(900);

	protected int code;
	private Object data;
	private String message;

	protected ResponseDataWrapper(int code, Object data, String msg) {
		this.code = code;
		this.data = data;
		this.message = msg;
	}

	protected ResponseDataWrapper(int code, String msg) {
		this.code = code;
		this.message = msg;
	}

	protected ResponseDataWrapper(int i) {
		this.code = i;
	}

	public int getCode() {
		return code;
	}

	public Object getData() {
		return data;
	}

	public String getMessage() {
		return message;
	}

	public ResponseDataWrapper wrapMessage(String message) {
		return new ResponseDataWrapper(this.code, this.data, message);
	}

	public ResponseDataWrapper wrapMessage(String message, int code) {
		return new ResponseDataWrapper(code, this.data, message);
	}

	public ResponseDataWrapper wrapMessage(String message, Object... param) {
		return new ResponseDataWrapper(code, this.data, MessageFormat.format(message, param));
	}

	public ResponseDataWrapper wrapData(Object data) {
		return new ResponseDataWrapper(this.code, data, this.message);
	}

	public ResponseDataWrapper wrapData(String key, Object value) {
		HashMap<String, Object> map = new HashMap<>(1);
		map.put(key, value);
		return new ResponseDataWrapper(this.code, map, this.message);
	}

	public boolean isSucc() {
		return this.code == 200;
	}
}
